// pages/centerAdd/centerAdd.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userAdd:[],
    newadd:'',
  },
  onLoad:function(){
    //获取用户id发送请求
    var userid = wx.getStorageSync("OoOoUserid");
    var data = {
      userid:userid,
    }
    var that = this;
    //获取个人资料信息
    wx.request({
      url:'http://47.104.142.216/TP/public/index.php/index/Usercenter/index_lwx',
      dataType:'json',
      method:'POST',
      data:data,
      header:{
        'content-type':'application/x-www-form-urlencoded'
      },
      success:function(res){
          that.setData({
            //第一个data为固定用法
            userAdd: res.data
          })
        },
        fail:function(err){
        console.log(err)
        }
    });
  },
  saveaddBtn:function(e){
    var that = this;
    if(e.detail.value.newadd == ''){
      wx.showToast({
        title: '请输入新地址',
        icon: 'none',
        duration: 2000
      })
      return;
    }
   var newsite = e.detail.value.newadd;
   var userid = wx.getStorageSync("OoOoUserid");
   var data = {
    newSite : newsite,
    userId : userid,
  }

  //修改地址

  wx.request({
    url:'http://47.104.142.216/TP/public/index.php/index/Usercenter/updateUserSite',
    dataType:'json',
    method:'POST',
    data:data,
    header:{
      'content-type':'application/x-www-form-urlencoded'
    },
    success:function(res){
        if(res.data){
          wx.showToast({
            title: '修改成功',
            icon: 'success',
            duration: 2000
          })

          that.onLoad()
          return;
        }
      },
      fail:function(err){
      console.log(err)
      }
  });

  }
})